local TestController = {}
local vaild = require 'library.vaild'
local cache = require ('library.cache'):new()
local configobj = require ('library.config')




function TestController:cache()
    cache:set('test',{'test1','test2'},300);
    local x=cache:get('test');
    if x then
        print_r(x)
    end
    return ""
end

function TestController:index()
    local get=self:getRequest():GET()
    local local_vaild=vaild:new(get);
    --http://127.0.0.100/test/index?email=jlzan1314@163.com&abc=abc&max=123&min=123456&int=-1&xxx=5&test=2
    local_vaild:add('test',"eq(2)",'must be eq=2')
    local_vaild:add('email',"required|email",'email')
    local_vaild:add('abc',"required|alpha",'alpha')
    local_vaild:add('min',"required|min_length(5)",'min_length')
    local_vaild:add('max',"required|max_length(5)",'max_length')
    local_vaild:add('int',"required|int",'int')
    local_vaild:add('xxx',"required|xxx",'xxx=5')

    local_vaild:add_function('xxx',function( data )
        if data=='5' then
            return true
        end
        return false
    end)

    if local_vaild:run() then
        return 'yes'
    end

    print_r(local_vaild:get_errors())

    return 'no'
end

function TestController:testif()
    --http://127.0.0.100/test/testif
    print_r('a'=='b') --false
    print_r(1=='1') --false
    print_r(1==tonumber('1')) --true
    print_r(tostring(1)=='1') --true
    print_r(not not 1) --true
    
    return '-------------------------test end'
end

function TestController:testflush()
    for i=1,10 do
        ngx.say('1')
        ngx.flush()
        ngx.sleep(1)
    end
end

function TestController:test(  )
    return 'hello'
end

function TestController:config(  )
    local c=configobj:new()
    print_r(c:get('index_cache'));
    return 'success'
end

function TestController:cookie()
    local cookie = require ('vanilla.v.libs.cookie'):new()
     local ok,error=cookie:set('user_name','this is user_name' ,600)
     if not ok then
        print_r(error)
     end
     return ''
end

function TestController:getcookie()
    local cookie = require ('vanilla.v.libs.cookie'):new()
    local ok,error = cookie:get('user_name')
     if not ok then
        print_r(error)
     end
     print_r(cookie:get_all())
     print_r(ok)
     return ''
end
return TestController
